
OUTPUT=$(shell mkdir -p $(PWD)/output; echo $(PWD)/output)

SRCS =threadlog.c threadpool.c demo.c

all: libthreadpool.so libthreadpool.a demo

CFLAGS += -g
LDLIBS += -lpthread

libthreadpool.so: $(OUTPUT)/threadlog.o $(OUTPUT)/threadpool.o
	$(CC) -shared -fPIC ${CFLAGS} -o $@ $^ -lc -ldl

libthreadpool.a:$(OUTPUT)/threadlog.o $(OUTPUT)/threadpool.o
	$(AR) rcs $@ $^

$(OUTPUT)/threadlog.o :threadlog.c threadlog.h threadpool.h
	$(CC) -c -fPIC ${CFLAGS} -o $@ $<

$(OUTPUT)/threadpool.o :threadpool.c threadlog.h threadpool.h
	$(CC) -c -fPIC ${CFLAGS} -o $@ $<

$(OUTPUT)/demo.o:demo.c threadlog.h threadpool.h
	$(CC) -c -fPIC ${CFLAGS} -o $@ $<

demo: $(OUTPUT)/demo.o libthreadpool.so
	$(CC) $^ -o demo ${LDLIBS}

.PHONY:clean

clean:
	$(RM) $(OUTPUT)/* libthreadpool.so libthreadpool.a demo
